package com.ipc.app.web.controller;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.ipc.app.biz.InformationBiz;
import com.ipc.app.constants.InformationTypeConstants;
import com.ipc.app.model.Information;
import com.ipc.app.model.Paginator;

@Controller
@RequestMapping(value = "/jsp/roundSearch.do")
public class RoundSearchAction {

	@Autowired
	private InformationBiz informationBiz;

	@RequestMapping(method = RequestMethod.GET)
	public String view() {
		return "roundSearch";
	}

	@RequestMapping(method = RequestMethod.POST)
	public String roundSearch(ModelMap model, String x, String y,
			String pageIndex) {
		if (StringUtils.isBlank(pageIndex)) {
			pageIndex = "1";
		}

		Paginator<Information> informations = informationBiz
				.getRoundInformation(x, y, InformationTypeConstants.CAR_OWNER,
						Integer.valueOf(pageIndex));

		model.addAttribute("x", x);
		model.addAttribute("y", y);
		model.addAttribute("informations", informations);
		return "roundSearchResult";
	}
}
